<template>
  <div class="project-table-view">
    <el-table
      :data="projectList"
      border
      empty-text="暂无数据"
      highlight-current-row
      stripe
      style="width: 100%;"
      @row-click="handleRowClick"
    >
      <el-table-column
        label="标题"
        prop="name"
        width="300"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          <i v-if="scope.row.type=='3'" class="iconfont icon-wenjianjia" />
          <span class="pl10 one-text-overflow">
            {{ scope.row.textName }}
          </span>
        </template>
      </el-table-column>
      <el-table-column
        label="提交答卷量"
        prop="submitCount"
      />
      <!-- <el-table-column
        align="center"
        label="描述"
        prop="describe"
        show-overflow-tooltip
      /> -->
      <el-table-column
        align="center"
        label="状态"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.type=='3'" />
          <span v-for="status in projectStatusList" v-else :key="status.code">
            <span
              v-if="status.code==scope.row.status"
            >
              {{ status.name }}
            </span>
          </span>
        </template>
      </el-table-column>
      <!-- <el-table-column
        align="center"
        label="类型"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.type=='3'" />
          <span v-else>
            <span>
              {{ getType(scope.row.type).name }}
            </span>
          </span>
        </template>
      </el-table-column> -->
      <el-table-column
        align="center"
        label="创建时间"
        prop="createTime"
      />
      <el-table-column
        align="center"
        label="更新时间"
        prop="updateTime"
      />
      <el-table-column label="操作">
        <template slot-scope="scope">
          <div v-if="scope.row.type=='3'">
            <el-button type="text" @click.stop="$emit('renameFolder',scope.row)">
              <i class="el-icon-edit" />
              重命名
            </el-button>
            <span @click="(e)=>{ e.stopPropagation()}">
              <el-popconfirm
                title="确定删除该文件夹吗？"
                @confirm="deleteForm(scope.row.formKey)"
              >
                <el-button slot="reference"
                           class="text-danger"
                           type="text"
                >
                  <i class="el-icon-delete" />
                  删除
                </el-button>
              </el-popconfirm>
            </span>
            <el-button type="text" @click.stop="$emit('downLoadFolder',scope.row)">
              <i class="el-icon-download" />
              导出数据
            </el-button>
          </div>
          <div v-else>
            <el-button type="text"
                       @click="toProjectHandle(scope.row,'editor',currentPage)"
            >
              <i class="el-icon-edit" />
              编辑
            </el-button>
            <span />
            <el-popconfirm
              v-if="scope.row.status==2"
              title="确定停止收集该项目吗？"
              @confirm="stopProject(scope.row.formKey)"
            >
              <el-button slot="reference"
                         class="text-danger"
                         type="text"
              >
                <i class="el-icon-video-pause" />
                停止
              </el-button>
            </el-popconfirm>
            <el-popconfirm
              v-if="scope.row.status!=2"
              title="确定删除该项目吗？"
              @confirm="logicDeleteForm(scope.row.formKey)"
            >
              <el-button slot="reference"
                         class="text-danger"
                         type="text"
              >
                <i class="el-icon-delete" />
                删除
              </el-button>
            </el-popconfirm>
            <el-dropdown trigger="click" placement="top">
              <el-button type="text">
                <i class="el-icon-arrow-down el-icon--right" />
                更多
              </el-button>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item v-if="scope.row.status!=1"
                                  icon="el-icon-data-analysis"
                                  @click.native="toProjectHandle(scope.row,'statistics',currentPage)"
                >
                  统计
                </el-dropdown-item>
                <el-dropdown-item v-if="!type" icon="el-icon-scissors" @click.native="()=>{$emit('move',scope.row)}">
                  移动到
                </el-dropdown-item>
                <el-dropdown-item v-if="!type" icon="el-icon-download" @click.native="()=>{$emit('downLoad',scope.row)}">
                  导出
                </el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import mixin from "./mixin"

export default {
  name: "MyFormTable",
  mixins: [mixin],
  props: {
    projectList: {
      type: Array,
      default: () => {
        return []
      }
    },
    // 我的问卷页还是协作页区分 默认为问卷页 协作页某些内容不显示
    type: {
      type: String,
      default: ''
    },
    currentPage:{
      default: ''
    }
  },
  methods: {
    handleRowClick(row, column, event) {
      if (row.type == 3) {
        this.$emit('enterFolder', row)
      }
    }
  }
}
</script>

<style scoped>

.project-table-view {
  margin-top: 20px;
  width: 90%;
}

.icon-wenjianjia {
  color: var(--color-primary);
}

.el-table tr {
  cursor: pointer;
}
</style>
